class Solution {
    public int[] singleNumber(int[] nums) {
        int ret = 0;
        for(int num : nums)
            ret ^= num;

        int x = (ret == Integer.MAX_VALUE ? ret : ret & (-ret));
        int x1 = 0,x2 = 0;
        for(int num : nums) {
            if((num & x) == 0) {
                x1 ^= num;
            }else {
                x2 ^= num;
            }
        }
        return new int[]{x1,x2};
    }
}